package com.kaibes.platform.article.admin;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaibes.platform.article.util.ArticleTagUtils;
import com.kaibes.platform.article.util.ArticleUtils;
import com.kaibes.platform.article.util.CategoryUtils;
import com.kaibes.platform.article.util.CommentUtils;
import com.kaibes.web.admin.AdminMenu;
import com.kaibes.web.admin.AdminMenuRes;
import com.kaibes.web.thymeleaf.ThymeleafConfig;

@Configuration
public class ArticleMenuInit implements InitializingBean {
    
    public final static String KEY = "article";
    
    @Autowired
    private ThymeleafConfig thymeleafConfig;
    
    @Autowired
    private ArticleUtils articleUtils;
    @Autowired
    private CommentUtils commentUtils;
    @Autowired
    private CategoryUtils categoryUtils;
    @Autowired
    private ArticleTagUtils articleTagUtils;
    
    @Bean
    public AdminMenu articleMenu() {
        AdminMenu parent = new AdminMenu();
        parent.setKey(KEY);
        parent.setName("文章模块");
        parent.setIcon("fas fa-file");
        parent.setHref("");
        parent.setSort(2);
        parent.setParentKey(AdminMenuRes.MENU_MAIN);
        return parent;
    }
    
    @Bean
    public AdminMenu articleEditMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("article-edit");
        menu.setName("文章编辑");
        menu.setIcon("fas fa-file-signature");
        menu.setHref("/admin/article/edit");
        menu.setSort(1);
        menu.setParentKey(KEY);
        return menu;
    }
    
    @Bean
    public AdminMenu articleViewMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("article-view");
        menu.setName("文章浏览");
        menu.setIcon("fas fa-file-alt");
        menu.setHref("/admin/article/view");
        menu.setSort(2);
        menu.setParentKey(KEY);
        return menu;
    }
    
    @Bean
    public AdminMenu articleCategoryMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("article-category");
        menu.setName("文章分类");
        menu.setIcon("fas fa-folder");
        menu.setHref("/admin/article/category");
        menu.setSort(3);
        menu.setParentKey(KEY);
        return menu;
    }
    
    @Bean
    public AdminMenu articleTagMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("article-tag");
        menu.setName("文章标签");
        menu.setIcon("fas fa-tag");
        menu.setHref("/admin/article/tag");
        menu.setSort(4);
        menu.setParentKey(KEY);
        return menu;
    }
    
    @Bean
    public AdminMenu commentManageMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("article-comment");
        menu.setName("评论管理");
        menu.setIcon("fas fa-comments");
        menu.setHref("/admin/article/comment");
        menu.setSort(5);
        menu.setParentKey(KEY);
        return menu;
    }
    
	@Override
	public void afterPropertiesSet() throws Exception {
		thymeleafConfig.putStaticVariable("articleUtils", articleUtils);
		thymeleafConfig.putStaticVariable("articleTagUtils", articleTagUtils);
		thymeleafConfig.putStaticVariable("categoryUtils", categoryUtils);
		thymeleafConfig.putStaticVariable("commentUtils", commentUtils);
	}
    
}
